import React from 'react'
import Goods from './Conmponent/Goods'
import Card from './Conmponent/Card'
import Axios from 'axios'
import {connect} from 'react-redux'
class App extends React.PureComponent{

  componentDidMount() {
    this.props.initCard()
  }
  render() {
    return (
      <div>
        <h1>进阶版购物车</h1>
        <div style={{display:'flex',justifyContent: 'space-around'}}>
          <Goods/>
          <Card/>
        </div>
      </div>
    )
  }
}

export default connect(
  null,
  (dispatch) => ({
    initCard () {
      Axios.get('http://localhost:9090/cards').then(res => {
        const {data} = res
        dispatch({
          type: 'INIT_TODO',
          data
        })
    })
    }
  })
)(App)